package com.szrt.club.manager;

import com.szrt.club.IPeople;

public class Club {
	
	//俱乐部数组
	private IPeople[] peopleArray;
	
	public IPeople[] getPeopleArray() {
		return peopleArray;
	}

	
	private int index;
	
	public Club(int len){
		peopleArray=new IPeople[len];
		System.out.println("创建一个俱乐部");
	}
	
	/**
	 * 添加会员
	 * @param people 会员
	 */
	public void add(IPeople people){
		
		int len=peopleArray.length;
		//添加的人该放在哪里
		for(int i=0;i<len;i++){
			if(null==peopleArray[i]){
				index=i;
				break;
			}
		}
		
		//判断人数是否满了
		if(index>len-1){
			System.out.println("人数满了添加失败、、");
		}else{
			peopleArray[index]=people;
			System.out.println("添加成功、、");
			
		}
	}

	
	/**
	 * 按照name搜索
	 * @param name 要搜索的名字
	 * @return 搜索到人的数组
	 */
	public IPeople[] searchByName(String name){
		
		int len=peopleArray.length;
		
		//要创建多大数组接收
		int counter=0;
		for(int i=0;i<len;i++){
			if(null!=peopleArray[i]){
				String peoname=peopleArray[i].getName();
				if(peoname.contains(name)){
					counter=counter+1;
				}
			}
		}
		
		IPeople[] newPeople=new IPeople[counter];
		if(counter==0){
			System.out.println("没有找打相关的人");
		}else{
			
			//创建接收查询到人的数组
			int xb=0;
			for(int i=0;i<len;i++){
				if(null!=peopleArray[i]){
					if(peopleArray[i].getName().contains(name)){
						newPeople[xb]=peopleArray[i];
						xb=xb+1;
					}
				}
			}
		}
		return newPeople;
	}
	
	
	

}
